<?php
class authanticatindao extends CI_Model{
	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}
	
	public function login($uname,$pass){
		$this->db->select('user_id');
		$this->db->from('user');
		$this->db->where('user_account_name',$uname);
		$this->db->where('user_password',$pass);
		$query = $this->db->get();
		if($query->num_rows() == 1){
			return $query->row('user_id');
		} else {
			return 0;
		}
	}

	public function signup(
			$user_account_name,
			$user_password,
			$user_name,
			$user_surname,
			$default_neighborhood,
			$user_email,
			$user_phone,
			$user_birthdate,
			$ismale,
			$role_id
			){
		$this->load->model('userdao');
		$user_result = $this->userdao->insertuser(
				$user_account_name,
				$user_password,
				$user_name,
				$user_surname,
				$default_neighborhood,
				$user_email,
				$user_phone,
				$user_birthdate,
				$ismale
		);
		if(!$user_result)
		{
			return false;
		}
		else {
			$return_id = $this->db->insert_id();
			array_push($data,
			array('user_id' => $return_id));
			$this->load->model('userhasroledao');
			$role_result = $this->userhasroledao->insert_role_to_user($user_id,$role_id);
			if(!$role_result){
				return false;
			}
			return $data;
		}
	}
/*	public function signup($user_account_name,$user_password,$user_name,$user_surname,
							$user_email,$user_phone,$user_birthdate,$sex,$role_id){
		$this->load->model('userdao');
		$user_result = $this->userdao->insertuser($user_name,$user_surname,$user_email,$user_phone,$user_birthdate,$sex);
		if(!$user_result){
			return false;
		}
		$user_id = $this->userdao->getbyemail($user_email); 
		$this->load->model('credentialsdao');
		$cred_result = $this->credentialsdao->insertcredential($user_id,$user_account_name,$user_password);
		if(!$cred_result){
			return false;
		}
		$this->load->model('userhasroledao');
		$role_result = $this->userhasroledao->insert_role_to_user($user_id,$role_id);
		if(!$role_result){
			return false;
		}
		return true;
	}
	*/
	
	
}
?>